<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>simExportMesh</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>

<body>

<div align="center">
<table class=allEncompassingTable >
 <tr>
  <td >
<p><a href="../../index.html" TARGET="_top"><img src="../images/homeImg.png"></a></p>

<h1>Regular API function</h1>
<h3 class=subsectionBar><a name="simExportMesh" id="simExportMesh"></a>simExportMesh / sim.exportMesh </h3>
<table class=apiTable>
<tr class=apiTableTr> 
<td class=apiTableLeftDescr>
Description 
</td> 
<td class=apiTableRightDescr>Exports a mesh to a file. See also <a href="simImportMesh.htm">sim.importMesh</a> and <a href="simGetShapeMesh.htm">sim.getShapeMesh</a><br></td>
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCSyn>
C synopsis
</td> 
<td class=apiTableRightCSyn>simInt simExportMesh(simInt fileformat,const simChar* pathAndFilename,simInt options,simFloat scalingFactor,simInt elementCount,simFloat** vertices,const simInt* verticesSizes,simInt** indices,const simInt* indicesSizes,simFloat** reserved,simChar** names)<br></td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCParam>C parameters</td> 
<td class=apiTableRightCParam>
<div><strong>fileformat</strong>: the fileformat to export to:</div>
<div class=tab>0: OBJ format</div>
<div class=tab>3: TEXT STL format</div>
<div class=tab>4: BINARY STL format</div>
<div class=tab>5: COLLADA format</div>
<div class=tab>6: TEXT PLY format</div>
<div class=tab>7: BINARY PLY format</div>
<div><strong>pathAndFilename</strong>: the location of the file to create.</div>
<div><strong>options</strong>: keep at 0</div>
<div><strong>scalingFactor</strong>: the scaling factor to apply to the vertices to export</div>
<div><strong>vertices</strong>: an array to vertice arrays. See the example below</div>
<div><strong>verticesSizes</strong>: an array indicating the individual vertice array sizes. See the example below</div>
<div><strong>indices</strong>: an array to indice arrays. See the example below</div>
<div><strong>indicesSizes</strong>: an array indicating the individual indice array sizes. See the example below</div>
<div><strong>reserved</strong>: reserved for future extensions. Keep at nullptr.</div>
<div><strong>names</strong>: Keep at nullptr</div>
<br>
<div>USAGE EXAMPLE:</div>
<pre class=lightBlueBoxNoMarginAndSmall>
// Exports all shapes in the scene
simInt shapeCount=0;
while (simGetObjects(shapeCount++,sim_object_shape_type)!=-1);
shapeCount--;
simFloat** vertices=new simFloat*[shapeCount];
simInt* verticesSizes=new simInt[shapeCount];
simInt** indices=new simInt*[shapeCount];
simInt* indicesSizes=new simInt[shapeCount];
simInt index=0;
while (true)
{
    simInt shapeHandle=simGetObjects(index++,sim_object_shape_type);
    if (shapeHandle&#60;0)
        break;
    simFloat* vert;
    simInt vertS;
    simInt* ind;
    simInt indS;
    simGetShapeMesh(shapeHandle,&vert,&vertS,&ind,&indS,nullptr);
    vertices[index-1]=vert;
    verticesSizes[index-1]=vertS;
    indices[index-1]=ind;
    indicesSizes[index-1]=indS;
    simFloat m[12];
    simGetObjectMatrix(shapeHandle,-1,m);
    for (simInt i=0;i&#60;vertS/3;i++)
    {
        simFloat v[3]={vert[3*i+0],vert[3*i+1],vert[3*i+2]};
        simTransformVector(m,v);
        vert[3*i+0]=v[0];
        vert[3*i+1]=v[1];
        vert[3*i+2]=v[2];
    }
}
simExportMesh(0,"d:\\example.obj",0,1,shapeCount,vertices,
                 verticesSizes,indices,indicesSizes,nullptr,nullptr);
for (simInt i=0;i&#60;shapeCount;i++)
{
    simReleaseBuffer((simChar*)vertices[i]);
    simReleaseBuffer((simChar*)indices[i]);
}
delete[] vertices;
delete[] verticesSizes;
delete[] indices;
delete[] indicesSizes;</pre>

</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftCRet>
C return value
</td> 
<td class=apiTableRightCRet>
<div>-1 if operation was not successful<br>
</div>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLSyn>
Lua synopsis
</td> 
<td class=apiTableRightLSyn>sim.exportMesh(int fileformat,string pathAndFilename,int options,float scalingFactor,table[] vertices,table[] indices)<br></td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLParam>Lua parameters</td> 
<td class=apiTableRightLParam>
<div><strong>fileformat</strong>: same as C function</div>
<div><strong>pathAndFilename</strong>: same as C function</div>
<div><strong>options</strong>: same as C function</div>
<div><strong>scalingFactor</strong>: same as C function</div>
<div><strong>vertices</strong>: a table of vertice tables. See the example below</div>
<div><strong>indices</strong>: a table of indice tables. See the example below</div>
<br>
<div>USAGE EXAMPLE (e.g. in a <a href="../customizationScripts.htm">customization script</a>):</div>
<pre class=lightRedBoxNoMarginAndSmall>
-- Exports all shapes in the scene
if (exportButtonPressed) then
    allVertices={}
    allIndices={}
    shapeIndex=0
    while (true) do
        h=sim.getObjects(shapeIndex,sim.object_shape_type)
        if (h&#60;0) then
            break
        end
        shapeIndex=shapeIndex+1
        vertices,indices=sim.getShapeMesh(h)
        m=sim.getObjectMatrix(h,-1)
        for i=1,#vertices/3,1 do
            v={vertices[3*(i-1)+1],vertices[3*(i-1)+2],vertices[3*(i-1)+3]}
            v=sim.multiplyVector(m,v)
            vertices[3*(i-1)+1]=v[1]
            vertices[3*(i-1)+2]=v[2]
            vertices[3*(i-1)+3]=v[3]
        end
        table.insert(allVertices,vertices)
        table.insert(allIndices,indices)
    end
    if (#allVertices>0) then
        sim.exportMesh(0,"d:\\example.obj",0,1,allVertices,allIndices)
    end
end</pre>
</td> 
</tr> 
<tr class=apiTableTr> 
<td class=apiTableLeftLRet>
Lua return values
</td> 
<td class=apiTableRightLRet>
<div>none</div></td> 
</tr> 
</table> 


<br>
</td>
</tr>
</table>
</div>
</body>
</html>
